﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace LastfmNet.Models
{
    public class Playlist : LastfmModelBase, IHasThreeImages
    {
        public Playlist()
        {
            this.Id = 0;
            this.Title = string.Empty;
            this.Description = string.Empty;
            this.Date = DateTime.MinValue;
            this.Size = 0;
            this.Duration = 0;
            this.Streamable = false;
            this.Creator = string.Empty;
            this.Url = string.Empty;
            this.ImageSmall = string.Empty;
            this.ImageMedium = string.Empty;
            this.ImageLarge = string.Empty;
        }

        public Playlist(XmlNode playlistNode)
            : this()
        {
            if (playlistNode == null) return;
            this.InitializeFromXmlNode(playlistNode);
        }

        public override void InitializeFromXmlNode(XmlNode node)
        {
            if (node == null) return;
            this.Id = node.GetChildValue("id").ToInteger();
            this.Title = node.GetChildValue("title");
            this.Description = node.GetChildValue("description");
            this.Date = node.GetChildValue("date").ToDateTime();
            this.Size = node.GetChildValue("size").ToInteger();
            this.Duration = node.GetChildValue("duration").ToInteger();
            this.Streamable = node.GetChildValue("streamable").ToBoolean();
            this.Creator = node.GetChildValue("creator");
            this.Url = node.GetChildValue("url");
            this.ImageSmall = node.GetChildValueWithSpecialAtrribute("image", "size", "small");
            this.ImageMedium = node.GetChildValueWithSpecialAtrribute("image", "size", "medium");
            this.ImageLarge = node.GetChildValueWithSpecialAtrribute("image", "size", "large");
        }

        public int Id
        {
            get;
            set;
        }

        public string Title
        {
            get;
            set;
        }

        public string Description
        {
            get;
            set;
        }

        public DateTime Date
        {
            get;
            set;
        }

        public int Size
        {
            get;
            set;
        }

        public int Duration
        {
            get;
            set;
        }

        public bool Streamable
        {
            get;
            set;
        }

        public string Creator
        {
            get;
            set;
        }

        public string Url
        {
            get;
            set;
        }

        public string ImageSmall
        {
            get;
            set;
        }

        public string ImageMedium
        {
            get;
            set;
        }

        public string ImageLarge
        {
            get;
            set;
        }
    }
}
